package com.chanzany.interpreter;

/**
 * @Author ChanZany
 * @Date 2021/10/20 13:17
 * @Version 1.0
 * 加法表达式类（非终结符表达式）
 */
public class Plus extends AbstractExpression {
    //+号左右两边的表达式
    private AbstractExpression left;
    private AbstractExpression right;


    public Plus(AbstractExpression lest, AbstractExpression right) {
        this.left = lest;
        this.right = right;
    }

    //将左边表达式的结果和右边表达式的结果进行相加
    @Override
    public int interpret(Context context) {
        return left.interpret(context) + right.interpret(context);
    }

    @Override
    public String toString() {
        return "("+left.toString()+" + "+right.toString()+")";
    }
}
